<?php

namespace app\common\service\learn;

use app\common\enums\AccountTypeEnum;
use app\common\enums\say\LearnSayTestFullTypeEnum;
use app\common\enums\say\SayCategoryTypeEnum;
use app\common\model\banxi\core\CoreSayVocabularySetting;
use app\common\model\banxi\Grade;
use app\common\model\banxi\learn\LearnSayVocabularyAnswerRecord;
use app\common\model\banxi\learn\LearnSayVocabularyRecord;
use app\common\model\banxi\organization\Organization as OrganizationModel;
use app\common\model\banxi\say\SayGrade;
use app\common\model\banxi\say\SayGrade as SayGradeModel;
use app\common\model\banxi\student\Student;
use app\common\model\banxi\student\StudentExtra;
use app\common\service\AccountService;
use app\common\service\ApiService;
use app\common\service\ConfigService;
use ba\Exception;
use think\db\exception\PDOException;
use think\exception\ValidateException;
use think\facade\Db;

class LearnSayVocabularyService extends ApiService
{

    /**
     * 开始词汇测试
     *
     * @param string|int $accountId 账户ID
     * @param string|int $accountType 账户类型
     * @param int|null $skRecordId 学习记录ID
     * @param int|null $tutorTrainerId 辅导教练ID
     * @return array|\think\response\Json
     */
    // public function startVocabulary1($categoryId, $accountId, $accountType, $skRecordId, $tutorTrainerId)
    // {
    //     // 获取词汇设置和范围配置
    //     $GradeModel = new SayGradeModel();
    //     $vocabularySentenceList = $GradeModel->with([
    //         'teachSentenceList' => function ($query) {
    //             $query->where(['parentId' => 0])->orderRaw('RAND()')->field('id,gradeId,sentenceEn,sentenceZh,sentenceAudio,sentenceWordColor')->limit(4);
    //         }])->where(['sayCategoryId' => $categoryId])->select();
    //     if (empty($vocabularySentenceList)) {
    //         getResponseException('句型量检查配置为空', [], 1, 'ERROR');
    //     }
    //
    //
    //     // 获取账户信息
    //     $AccountService = new AccountService();
    //     $accountInfo = $AccountService->getAccountInfo($accountId, $accountType);
    //     if (empty($accountInfo)) {
    //         getResponseException('账户不存在', [], 1, 'ERROR');
    //     }
    //
    //     // 创建测试记录
    //     $vocabularyRecord = [
    //         'del' => 0,
    //         'skRecordId' => $skRecordId ?: null,
    //         'accountId' => $accountId,
    //         'sayCategoryId' => $categoryId,
    //         'accountType' => $accountType,
    //         'organizationId' => $accountInfo['organizationId'],
    //         'tutorTrainerId' => $tutorTrainerId ? $tutorTrainerId : null,
    //         'studentId' => ($accountType == 3) ? $accountId : null,
    //         'trainerId' => ($accountType == 4) ? $accountId : null,
    //         'isSubmit' => 0,
    //         // 'suggest' => '',
    //         'startTime' => date('Y-m-d H:i:s', time())
    //     ];
    //     $LearnVocabularyRecordModel = new LearnSayVocabularyRecord();
    //     $recordId = $LearnVocabularyRecordModel->create($vocabularyRecord);
    //
    //     // 构造题目列表
    //     $answerList = [];
    //     foreach ($vocabularySentenceList as $value) {
    //         foreach ($value['teachSentenceList'] as $item) {
    //             $question = [
    //                 'basicScore' => $value['basicScore'],//基础分
    //                 'sentenceEn' => $item['sentenceEn'],
    //                 'sentenceZh' => $item['sentenceZh'],
    //                 'sentenceAudio' => $item['sentenceAudio'],
    //                 'sentenceWordColor' => $item['sentenceWordColor'] ? json_decode($item['sentenceWordColor'], true) : [],
    //                 'userAnswer' => ''
    //             ];
    //             $answerList[] = $question;
    //         }
    //     }
    //
    //     return [
    //         'recordId' => $recordId->id,
    //         'accountId' => $accountId,
    //         'accountType' => $accountType,
    //         'answerList' => $answerList
    //     ];
    // }

    public function startVocabulary($testFullType, $accountId, $accountType, $skRecordId, $tutorTrainerId)
    {
        // 获取词汇设置和范围配置
        $configService = new ConfigService();
        $vocabularyGradeLimit = $configService->getSysConfigValue('vocabulary_grade_limit');
        $GradeModel = new SayGradeModel();
        $vocabularySentenceList = $GradeModel->alias('g')->with([
            'teachSentenceList' => function ($query) use ($vocabularyGradeLimit, $testFullType) {
                $subQuery = $query->where(['parentId' => 0])
                    ->field('id,name,gradeId,sentenceEn,sentenceZh,sentenceAudio,sentenceWordColor')
                    ->limit($vocabularyGradeLimit);
                if ($testFullType == LearnSayTestFullTypeEnum::E2) {
                    $subQuery->order(['sortNum' => 'asc']);
                } else {
                    $subQuery->orderRaw('RAND()');
                }
                return $subQuery;
            }])->whereExists(function ($query) use ($testFullType) {
            $subQuery = $query->name('banxi_say_category')
                ->whereColumn('id', 'g.sayCategoryId');
            if ($testFullType == LearnSayTestFullTypeEnum::E2) {
                $subQuery->where('type', '=', SayCategoryTypeEnum::E3);
            } else {
                $subQuery->where('type', '=', SayCategoryTypeEnum::E1);
            }
            return $subQuery;
        })->order(['sortNum' => 'asc'])->select();
        if (empty($vocabularySentenceList)) {
            getResponseException('句型量检查配置为空', [], 1, 'ERROR');
        }

        // 获取账户信息
        $AccountService = new AccountService();
        $accountInfo = $AccountService->getAccountInfo($accountId, $accountType);
        if (empty($accountInfo)) {
            getResponseException('账户不存在', [], 1, 'ERROR');
        }

        Db::startTrans();
        try {
            // 创建测试记录
            $vocabularyRecord = [
                'del' => 0,
                'skRecordId' => $skRecordId ?: null,
                'accountId' => $accountId,
                'sayCategoryId' => 0,
                'testFullType' => $testFullType,
                'accountType' => $accountType,
                'organizationId' => $accountInfo['organizationId'],
                'tutorTrainerId' => $tutorTrainerId ?: null,
                'studentId' => ($accountType == 3) ? $accountId : null,
                'trainerId' => ($accountType == 4) ? $accountId : null,
                'isSubmit' => 0,
                'startTime' => date('Y-m-d H:i:s', time())
            ];
            $LearnVocabularyRecordModel = new LearnSayVocabularyRecord();
            $recordResult = $LearnVocabularyRecordModel->create($vocabularyRecord);
            // 构造题目列表
            $answerList = $this->buildAnswerList($vocabularySentenceList);

            Db::commit();
        } catch (Exception|PDOException|ValidateException $e) {
            Db::rollback();
            getResponseException($e->getMessage(), [], 1, 'ERROR');
        }
        return [
            'recordId' => $recordResult->id,
            'accountId' => $accountId,
            'accountType' => $accountType,
            'answerList' => array_values($answerList)
        ];
    }

    /**
     * 构造题目列表
     */
    private function buildAnswerList($vocabularySentenceList)
    {
        $answerList = [];
        foreach ($vocabularySentenceList as $gradeInfo) {
            if (empty($gradeInfo['teachSentenceList'])) {
                continue;
            }
            foreach ($gradeInfo['teachSentenceList'] as $sentenceItem) {
                if (!isset($answerList[$sentenceItem['gradeId']])) {
                    $answerList[$sentenceItem['gradeId']] = [
                        'gradeId' => $sentenceItem['gradeId'],
                        'question' => []
                    ];
                }

                $answerList[$sentenceItem['gradeId']]['question'][] = [
                    'basicScore' => 0,
                    'name' => $sentenceItem['name'],
                    'sentenceEn' => $sentenceItem['sentenceEn'],
                    'sentenceZh' => $sentenceItem['sentenceZh'],
                    'sentenceAudio' => $sentenceItem['sentenceAudio'],
                    'sentenceWordColor' => $sentenceItem['sentenceWordColorList'],
                    'gradeId' => $sentenceItem['gradeId'],
                    'userAnswer' => ''
                ];
            }
        }
        return $answerList;
    }

    /**
     * 提交词汇测试结果
     *
     * @param int $studentId 学生ID
     * @param int $trainerId 教师ID
     * @param array $answerList 提交数据
     * @param array $recordId 测试记录
     * @return array|\think\response\Json
     */
    public function submitVocabulary($accountId, $accountType, $answerList, $recordId)
    {
        if (empty($recordId)) {
            getResponseException('测试记录不存在', [], 1, 'ERROR');
        }

        // 验证测试记录是否存在且未提交
        $learnSayVocabularyRecordModel = new LearnSayVocabularyRecord();
        $vocabularyRecordRaw = $learnSayVocabularyRecordModel->where(['id' => $recordId])
            ->where(function ($query) use ($accountId, $accountType) {
                if ($accountType == AccountTypeEnum::STUDENT) {
                    $query->where('studentId', $accountId);
                }
                if ($accountType == AccountTypeEnum::TRAINER) {
                    $query->where('trainerId', $accountId);
                }
            })->find();

        if (empty($vocabularyRecordRaw)) {
            getResponseException('测试记录不存在', [], 1, 'ERROR');
        }

        if ($vocabularyRecordRaw['isSubmit'] == 1) {
            getResponseException('测试已提交', [], 1, 'ERROR');
        }

        $questionList = $answerList ?? [];
        if (empty($questionList)) {
            getResponseException('答题记录为空', [], 1, 'ERROR');
        }
        Db::startTrans();
        try {
            // 统计答题情况并构建答题记录
            $scoreDetail = $this->initializeScoreDetail();
            $answerRecordList = $this->buildAnswerRecordList($questionList, $recordId, $scoreDetail);

            // 评估英语水平和词汇量水平
            $questionList = array_reverse($questionList);
            //真英语
            $englishGradeId = $this->evaluateEnglishLevel($questionList);
            //词汇量
            $wordGradeId = $this->evaluateVocabularyLevel($questionList);

            // 获取等级信息
            $gradeModel = new SayGradeModel();
            $questionListCount = count($questionList);
            if ($englishGradeId != -1) {
                // 获取真英语等级信息
                $englishGradeInfo = $gradeModel->where(['id' => $englishGradeId])->find();
                if (!$englishGradeInfo) {
                    throw new ValidateException('真英语等级获取失败');
                }
                // 获取更高一级的真英语等级
                $englishGradeLargerInfo = $this->getHigherGradeInfo($gradeModel, $englishGradeInfo, $vocabularyRecordRaw);
                if ($englishGradeLargerInfo) {
                    $englishGradeId = $englishGradeLargerInfo['id'];
                    $englishGradeInfo = $englishGradeLargerInfo;
                }
            } else {
                $englishGradeId = $questionList[$questionListCount - 1]['gradeId'];
                $englishGradeInfo = $gradeModel->where(['id' => $englishGradeId])->find();
                if (!$englishGradeInfo) {
                    throw new ValidateException('真英语等级获取失败');
                }
            }

            // 获取词汇量等级信息
            if ($wordGradeId != -1) {
                $wordGradeInfo = $gradeModel->where(['id' => $wordGradeId])->find();
                if (!$wordGradeInfo) {
                    throw new ValidateException('词汇量等级获取失败');
                }

                // 获取更高一级的词汇量等级
                $wordGradeLargerInfo = $this->getHigherGradeInfo($gradeModel, $wordGradeInfo, $vocabularyRecordRaw);
                if ($wordGradeLargerInfo) {
                    $wordGradeId = $wordGradeLargerInfo['id'];
                    $wordGradeInfo = $wordGradeLargerInfo;
                }
            } else {
                $wordGradeId = $questionList[$questionListCount - 1]['gradeId'];
                $wordGradeInfo = $gradeModel->where(['id' => $wordGradeId])->find();
                if (!$wordGradeInfo) {
                    throw new ValidateException('词汇量等级获取失败');
                }
            }


            $endTime = time();
            $testDuration = $endTime - strtotime($vocabularyRecordRaw['startTime']);

            // 更新测试记录
            $vocabularyRecordUpdate = [
                'score' => 0,
                'scoreDetail' => json_encode(array_values($scoreDetail), JSON_UNESCAPED_UNICODE),
                'level' => $englishGradeId,
                'wordLevel' => $wordGradeId,
                'countWord' => 0,
                'isSubmit' => 1,
                'endTime' => date("Y-m-d H:i:s", $endTime),
                'testDuration' => $testDuration,
                'updateTime' => $endTime
            ];


            // 更新测试记录
            $learnSayVocabularyRecordModel->update($vocabularyRecordUpdate, ['id' => $recordId]);

            // 批量保存答题记录
            if (!empty($answerRecordList)) {
                $learnSayVocabularyAnswerRecordModel = new LearnSayVocabularyAnswerRecord();
                $chunks = array_chunk($answerRecordList, 100);
                foreach ($chunks as $chunk) {
                    $learnSayVocabularyAnswerRecordModel->insertAll($chunk);
                }
            }

            // 更新学生英语水平信息
            if ($accountType == AccountTypeEnum::STUDENT) {
                $student = Student::where(['id' => $vocabularyRecordRaw['studentId']])->find();
                if ($student) {
                    $student->englishLevel = $englishGradeInfo['name'];
                    $student->wordsLevel = $wordGradeInfo['name'];
                    $student->save();

                    $studentExtraModel = new StudentExtra();
                    $studentExtraModel->update([
                        'englishLevel' => $englishGradeInfo['name'],
                    ], ['studentId' => $vocabularyRecordRaw['studentId']]);
                }
            }

            Db::commit();
        } catch (Exception|PDOException|ValidateException $e) {
            Db::rollback();
            getResponseException('数据保存失败: ' . $e->getMessage(), [], 1, 'ERROR');
        }
        return $recordId;
    }

    /**
     * 初始化答题统计详情
     */
    private function initializeScoreDetail()
    {
        return [
            'A' => ['key' => 'A', 'num' => 0],
            'B' => ['key' => 'B', 'num' => 0],
            'C' => ['key' => 'C', 'num' => 0],
            'D' => ['key' => 'D', 'num' => 0],
            'E' => ['key' => 'E', 'num' => 0],
        ];
    }

    /**
     * 构建答题记录列表并统计得分
     */
    private function buildAnswerRecordList($questionList, $recordId, &$scoreDetail)
    {
        $answerRecordList = [];

        foreach ($questionList as $item) {
            foreach ($item['question'] as $it) {
                $userAnswer = $it['userAnswer'];

                // 验证用户答案是否有效并统计
                if (in_array($userAnswer, ['A', 'B', 'C', 'D', 'E'])) {
                    $scoreDetail[$userAnswer]['num'] += 1;
                }
                $answerRecord = [
                    'recordId' => $recordId,
                    'del' => 0,
                    'sentenceEn' => $it['sentenceEn'],
                    'sentenceZh' => $it['sentenceZh'],
                    'sentenceAudio' => $it['sentenceAudio'],
                    'userAnswer' => $it['userAnswer'],
                    'createTime' => time(),
                    'basicScore' => 0,
                    'gradeId' => $it['gradeId'],
                    'score' => 0
                ];
                $answerRecordList[] = $answerRecord;
            }
        }

        return $answerRecordList;
    }

    /**
     * 评估真英语水平等级
     */
    private function evaluateEnglishLevel($questionList)
    {
        $englishEndIndex = -1;

        foreach ($questionList as $key => $item) {
            $englishCount = 0;
            foreach ($item['question'] as $value) {
                if (in_array($value['userAnswer'], ['A', 'B'])) {
                    $englishCount++;
                }
            }
            if ($englishCount >= 4) {
                $englishEndIndex = $key;
                break;
            }
        }

        return ($englishEndIndex !== -1) ?
            $questionList[$englishEndIndex]['gradeId'] :
            $englishEndIndex;
    }

    /**
     * 评估词汇量水平等级
     */
    private function evaluateVocabularyLevel($questionList)
    {
        $wordEndIndex = -1;

        foreach ($questionList as $key => $item) {
            $wordCount = 0;
            foreach ($item['question'] as $value) {
                if (in_array($value['userAnswer'], ['A', 'B', 'C'])) {
                    $wordCount++;
                }
            }
            if ($wordCount >= 4) {
                $wordEndIndex = $key;
                break;
            }
        }

        return ($wordEndIndex !== -1) ?
            $questionList[$wordEndIndex]['gradeId'] :
            $wordEndIndex;
    }

    /**
     * 获取更高一级的等级信息
     */
    private function getHigherGradeInfo($gradeModel, $currentGradeInfo, $vocabularyRecordRaw)
    {
        $where = [
            ['a.key', '>', $currentGradeInfo['key']],
        ];

        if ($vocabularyRecordRaw['testFullType'] == LearnSayTestFullTypeEnum::E2) {
            $where[] = ['b.type', '=', SayCategoryTypeEnum::E3];
        } else {
            $where[] = ['b.type', '=', SayCategoryTypeEnum::E1];
        }

        return $gradeModel->alias('a')
            ->join('banxi_say_category b', 'a.sayCategoryId = b.id')
            ->where($where)
            ->order('a.key', 'asc')
            ->field('a.id, a.name')
            ->find();
    }


    public function getVocabularyRecord($recordId)
    {
        $LearnSayVocabularyRecordModel = new LearnSayVocabularyRecord();
        $vocabularyRecord = $LearnSayVocabularyRecordModel
            ->where([
                'id' => $recordId,
                'isSubmit' => 1
            ])->find();
        if (empty($vocabularyRecord)) {
            getResponseException('未获取到记录', [], 1, 'ERROR');
        }
        // 获取账户信息
        $accountInfo = (new AccountService())->getAccountInfo($vocabularyRecord['accountId'], $vocabularyRecord['accountType']);
        if ($accountInfo && in_array($vocabularyRecord['accountType'], [AccountTypeEnum::STUDENT, AccountTypeEnum::TRAINER])) {
            $organizationModel = new OrganizationModel();
            if ($accountInfo['organizationId'] == 0) {
                $accountInfo['organizationBaseInfo'] = $organizationModel->getOrganizationInfo();
            } else {
                $accountInfo['organizationBaseInfo'] = $organizationModel->where('id', $accountInfo['organizationId'])->field('id,name,managerName')->find();
            }
            if ($vocabularyRecord['accountType'] == AccountTypeEnum::STUDENT) {
                $gradeModel = new Grade();
                $accountInfo['gradeInfo'] = $gradeModel->where('id', $accountInfo['gradeId'])->field('id,name,key')->find();
            }
        }
        $vocabularyRecord['accountInfo'] = $accountInfo;

        $testFullType = $vocabularyRecord['testFullType'];
        if ($testFullType == LearnSayTestFullTypeEnum::E3) {
            $revelInfo = CoreSayVocabularySetting::where(['id' => $vocabularyRecord['level']])->find();
            $vocabularyRecord['levelInfo'] = $revelInfo;
            $vocabularyRecord['suggest'] = $revelInfo ? $revelInfo['suggest'] : '';
            $vocabularyRecord['levelName'] = $revelInfo ? $revelInfo['rangeName'] . $revelInfo['rangeLevelCn'] : '';
            $vocabularyRecord['wordLevelName'] = '';
        } else {
            $sayGradeModel = new SayGrade();
            // 批量查询等级信息，减少数据库访问次数
            $gradeIds = array_filter([$vocabularyRecord['level'], $vocabularyRecord['wordLevel']]);
            $englishLevelInfo = null;
            $wordLevelInfo = null;

            if (!empty($gradeIds)) {
                $gradeInfos = $sayGradeModel->where('id', 'in', $gradeIds)->column('id,name,key', 'id');
                $englishLevelInfo = $gradeInfos[$vocabularyRecord['level']] ?? null;
                $wordLevelInfo = $gradeInfos[$vocabularyRecord['wordLevel']] ?? null;
            }
            $vocabularyRecord['levelInfo'] = $englishLevelInfo;
            $vocabularyRecord['levelName'] = $englishLevelInfo['name'] ?? '';
            $vocabularyRecord['wordLevelInfo'] = $wordLevelInfo;
            $vocabularyRecord['wordLevelName'] = $wordLevelInfo['name'] ?? '';
            $vocabularyRecord['suggest'] = $this->getSuggest($accountInfo, $vocabularyRecord['accountType'], $englishLevelInfo, $wordLevelInfo);
        }
        return $vocabularyRecord;
    }

    private function getSuggest($accountInfo, $accountType, $englishLevelInfo, $wordLevelInfo)
    {
        if ($accountType == AccountTypeEnum::TRAINER) {
            return '本次测试为教练测试,不提供学习建议';
        }

        if (empty($accountInfo['gradeId'])) {
            return '';
        }

        if (empty($englishLevelInfo) || empty($wordLevelInfo)) {
            return '';
        }

        if (empty($accountInfo['gradeInfo'])) {
            return '';
        }
        $gradeInfo = $accountInfo['gradeInfo'];
        $englishKey = $englishLevelInfo['key'];
        $wordKey = $wordLevelInfo['key'];
        $gradeKey = $gradeInfo['key'];

        // 使用 switch 或查找表替代多个 if 条件判断
        return $this->getSuggestionByLevelComparison($englishKey, $wordKey, $gradeKey);
    }

    private function getSuggestionByLevelComparison($englishKey, $wordKey, $gradeKey)
    {
        // 创建条件映射表
        $conditions = [
            // 您的真英语水平=当前年级，词汇量水平=当前年级
            [$englishKey == $gradeKey && $wordKey == $gradeKey, 'both_equal'],
            // 真英语水平=当前年级，词汇量水平>当前年级
            [$englishKey == $gradeKey && $wordKey > $gradeKey, 'english_equal_word_higher'],
            //真英语水平=当前年级，词汇量水平<当前年级
            [$englishKey == $gradeKey && $wordKey < $gradeKey, 'english_equal_word_lower'],
            // 真英语水平>当前年级，词汇量水平>当前年级
            [$englishKey > $gradeKey && $wordKey > $gradeKey, 'both_higher'],
            // 真英语水平>当前年级，词汇量水平<当前年级
            [$englishKey > $gradeKey && $wordKey < $gradeKey, 'english_higher_word_lower'],
            // 真英语水平>当前年级，词汇量水平=当前年级
            [$englishKey > $gradeKey && $wordKey == $gradeKey, 'english_higher_word_equal'],
            // 真英语水平<当前年级，词汇量水平<当前年级
            [$englishKey < $gradeKey && $wordKey < $gradeKey, 'both_lower'],
            // 真英语水平<当前年级，词汇量水平=当前年级
            [$englishKey < $gradeKey && $wordKey == $gradeKey, 'english_lower_word_equal'],
            // 真英语水平<当前年级，词汇量水平>当前年级
            [$englishKey < $gradeKey && $wordKey > $gradeKey, 'english_lower_word_higher'],
        ];

        foreach ($conditions as [$condition, $type]) {
            if ($condition) {
                return $this->getSuggestionText($type);
            }
        }
        return '';
    }

    private function getSuggestionText($type)
    {
        $suggestions = [
            //您的真英语水平=当前年级，词汇量水平=当前年级
            'both_equal' => '<p>建议您在听说强化方面：对本年级的核心句型进行巩固，同时可以开始高阶年级的内容学习。</p>
<p>词汇提升方面：基于本年级的核心内容强化和高年级的句型听说学习同时，顺便提升词汇量。</p>
<p>&nbsp;</p>
<p>综上所述：您的英语水平刚好符合本年级英语水平。</p>
<p>建议继续巩固本年级的学习内容，以及通过听力的输入路径，开始系统学习更高年级内容。</p>',
            //真英语水平=当前年级，词汇量水平>当前年级
            'english_equal_word_higher' => '<p>建议您在听说强化方面：可以开始进行高阶年级的核心句型听说强化。</p>
<p>词汇提升方面：基于高阶年级的核心句型听说学习，继续提升词汇量，强化词汇量优势。</p>
<p>&nbsp;</p>
<p>综上所述：您的英语水平稍高于本年级英语水平。</p>
<p>词汇储备已达当前年级要求，形成了扎实的词汇基础优势，听说水平与当前年级水平持平。建议继续通过听力的输入路径，开始系统学习更高年级内容。</p>',
            //真英语水平=当前年级，词汇量水平<当前年级

            'english_equal_word_lower' => '<p>综上所述：该学生大概率是能听会说，但看不懂文字。</p>',
            //真英语水平>当前年级，词汇量水平>当前年级

            'both_higher' => '<p>建议您在听说强化方面：可以进行高阶年级的核心句型听说强化。</p>
<p>词汇提升方面：基于高阶年级的核心句型听说学习，同时提升词汇量。</p>
<p>&nbsp;</p>
<p >综上所述：您的英语水平较高于目前本年级英语水平。</p>
<p >您的英语听说能力与词汇储备均超越当前年级水平，语言输入输出能力与词汇积累形成良性基础，具备向高阶年级突破的核心条件。建议抓住当前已有优势，利用当下宝贵时间，冲刺拔尖。</p>',

            //真英语水平>当前年级，词汇量水平<当前年级
            'english_higher_word_lower' => '',

            //真英语水平>当前年级，词汇量水平=当前年级
            'english_higher_word_equal' => '<p>综上所述：该学生大概率是能听会说，但看不懂文字。</p>',

            //真英语水平<当前年级，词汇量水平<当前年级
            'both_lower' => '<p>建议您在听说强化方面：从本年级及之前年级的核心句型开始，用听的输入方式，增加模仿练习，强化听力敏感度。</p>
<p>词汇提升方面：依托句子的输入，同步迅速拉升词汇量。</p>
<p>&nbsp;</p>
<p>综上所述：您的英语水平低于本年级英语水平。</p>
<p>目前正处于英语基础夯实阶段，词汇储备和听说能力暂时落后于当前年级，但这正是打牢根基、稳步追赶的好时机！只要跟着核心句型循序渐进，两者就能同步提升，很快就能跟上节奏！</p>',

            //真英语水平<当前年级，词汇量水平=当前年级
            'english_lower_word_equal' => '<p>建议您在听说强化方面：从本年级及之前年级的核心句型开始，用听的输入方式，增加模仿练习，强化听力敏感度。</p>
<p>词汇提升方面：不盲目新增词汇，聚焦当前年级的核心句型，激活词汇与句型，让词汇和句型深度绑定，从会认升级为会听会用。</p>
<p>&nbsp;</p>
<p>综上所述：您的英语水平稍低于本年级英语水平。</p>
<p>你已经扎实掌握了当前年级的核心词汇，这是超棒的基础优势！目前只是听说能力暂时没跟上词汇节奏，没法让积累的单词充分为沟通助力，但一定要从听开始，把词汇和听说精准绑定，很快就能实现综合能力的同步提升！</p>',

            //真英语水平<当前年级，词汇量水平>当前年级
            'english_lower_word_higher' => '<p>建议您在听说强化方面：从本年级及之前年级的核心句型开始，用听的输入方式，增加模仿练习，强化听力敏感度。</p>
<p>词汇提升方面：将单词和听说绑定，慢慢实现从“会认”到“会用 会听”的转变。</p>
<p>&nbsp;</p>
<p>综上所述：您的英语水平听说相对薄弱，词汇量较丰富。</p>
<p>同学您拥有超棒的词汇储备优势，已经打下了扎实的英语基础！目前只是暂时处于“会认不会用、听力反应稍慢”的阶段，导致听说能力暂时落后于当前年级水平，没能让丰富的词汇为沟通助力。但这只是成长路上的小插曲，只要把词汇和听说练习精准结合，让积累的单词“活”起来，你很快就能实现词汇储备与沟通能力的同步飞跃，在英语学习中收获满满的成就感，继续稳步精进！</p>',
        ];

        return $suggestions[$type] ?? '';
    }
}
